package com.caseProcess.controller;

import com.caseProcess.entity.Operation;
import com.caseProcess.entity.Result;
import com.caseProcess.entity.User;
import com.caseProcess.service.OperationService;
import com.caseProcess.utils.PagingUtil;
import com.caseProcess.utils.TimeUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author kittlen
 * @version 1.0
 * @date 2021年01月09日 15点15分
 */
@RestController
@RequestMapping("/operation")
public class OperationController {


    @Resource
    OperationService operationService;

    /**
     * 查询操作信息
     * @param operationId 操作id
     * @param operationUri 操作接口
     * @param operationUriName 接口名
     * @param policeId 操作者
     * @param page
     * @param limit
     * @param startTime
     * @param endTime
     * @return
     */
    @CrossOrigin
    @RequestMapping("/select")
    public Result select(@RequestParam(required = false,defaultValue = "0")long operationId,
                         @RequestParam(required = false,defaultValue = "")String operationUri,
                         @RequestParam(required = false,defaultValue = "")String operationUriName,
                         @RequestParam(required = false,defaultValue = "")String policeId,
                         @RequestParam(required = false,defaultValue = "0")int page,
                         @RequestParam(required = false,defaultValue = "0")int limit,
                         @RequestParam(required = false,defaultValue = "")String startTime,
                         @RequestParam(required = false,defaultValue = "")String endTime){
        Result result = new Result();
        Operation operation=new Operation();
        operation.setOperationId(operationId);
        operation.setOperationUri(operationUri);
        operation.setOperationUriName(operationUriName);
        User user=new User();
        user.setPoliceId(policeId);
        operation.setUser(user);
        endTime="".equals(endTime)? TimeUtil.getNowTime():endTime;
        endTime=TimeUtil.getSpecifiedDayAfter(endTime);
        List<Operation> list=operationService.selectOperation(operation,startTime,endTime);
        result.setCount(list.size());
        if(page!=0&&limit!=0){
            list= PagingUtil.paging(list,page,limit);
        }
        result.setData(list);
        return result;
    }


}
